package com.gking.processHarvest.common;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class Res<T> {

    private Integer code; //编码：1成功，0和其它数字为失败

    private String message; //错误信息

    private T data; //数据

    private Map map = new HashMap(); //动态数据


    public static <T> Res<T> success(String msg, T data) {
        Res<T> r = new Res<T>();
        r.data = data;
        r.code = 200;
        r.message = msg;
        return r;
    }

    public static <T> Res<T> success(String msg) {
        Res<T> r = new Res<T>();
        r.code = 200;
        r.message = msg;
        return r;
    }

    public static <T> Res<T> error(String msg) {
        Res r = new Res();
        r.message = msg;
        r.code = 500;
        return r;
    }

    public Res<T> add(String key, Object value) {
        this.map.put(key, value);
        return this;
    }

}
